package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.domain.AbandonStudent;
import cn.wolfcode.crm.domain.PayManage;
import cn.wolfcode.crm.query.QueryObject;
import cn.wolfcode.crm.service.IAbandonStudentService;
import cn.wolfcode.crm.util.JSONResult;
import cn.wolfcode.crm.util.PageResult;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("abandonStudent")
public class AbandonStudentController {
    @Autowired
    public IAbandonStudentService abandonStudentService;

    @RequestMapping("view")
    @RequiresPermissions(value = {"abandonStudent:view","流失学员列表"},logical = Logical.OR)
    public String view() {
        return "abandonStudent/abandonStudent";
    }

    @ResponseBody
    @RequestMapping("query")
    public PageResult query(QueryObject qo) {

        return abandonStudentService.query(qo);
    }

    @RequestMapping("selectAll")
    @ResponseBody
    public List<AbandonStudent> selectAll() {
        return abandonStudentService.selectAll();
    }

    @RequestMapping("delete")
    @RequiresPermissions(value = {"abandonStudent:delete","流失学员删除"},logical = Logical.OR)
    @ResponseBody
    public JSONResult delete(Long id) {
        try {
            abandonStudentService.deleteByPrimaryKey(id);
            return JSONResult.success("");
        } catch (Exception e) {
            e.printStackTrace();
            return JSONResult.mark("删除失败");
        }
    }
    @RequestMapping("audit")
    @RequiresPermissions(value = {"abandonStudent:audit","流失学员审核"},logical = Logical.OR)
    @ResponseBody
    public JSONResult audit(Long abandonStudentId, PayManage payManage) {
        try {
            abandonStudentService.audit(abandonStudentId,payManage);
            return JSONResult.success("");
        } catch (Exception e) {
            e.printStackTrace();
            return JSONResult.mark("删除失败");
        }
    }
    @ResponseBody
    @RequestMapping("saveOrUpdate")
    @RequiresPermissions(value = {"abandonStudent:saveOrUpdate","流失学员新增或编辑"},logical = Logical.OR)
    public JSONResult saveOrUpdate(AbandonStudent abandonStudent){
        try {
            if(abandonStudent.getId() != null){
                abandonStudentService.updateByPrimaryKey(abandonStudent);
            }else{
                abandonStudentService.insert(abandonStudent);
            }
            return JSONResult.success("");
        } catch (Exception e) {
            e.printStackTrace();
            return JSONResult.mark("操作失败");
        }
    }
}
